package com.gedeshidai.shumadevelop.controller;

import cn.hutool.core.date.DateTime;
import com.gedeshidai.shumadevelop.annotation.AuthCheck;
import com.gedeshidai.shumadevelop.common.BaseResponse;
import com.gedeshidai.shumadevelop.common.ErrorCode;
import com.gedeshidai.shumadevelop.common.ResultUtils;
import com.gedeshidai.shumadevelop.constant.UserConstant;
import com.gedeshidai.shumadevelop.exception.BusinessException;
import com.gedeshidai.shumadevelop.model.dto.user.CheckRequest;
import com.gedeshidai.shumadevelop.model.entity.History;
import com.gedeshidai.shumadevelop.model.entity.Product;
import com.gedeshidai.shumadevelop.model.entity.User;
import com.gedeshidai.shumadevelop.model.enums.HistoryStatusEnum;
import com.gedeshidai.shumadevelop.model.enums.ProductCheckStateEnum;
import com.gedeshidai.shumadevelop.model.enums.ProductOnlineStateEnum;
import com.gedeshidai.shumadevelop.service.HistoryService;
import com.gedeshidai.shumadevelop.service.ProductService;
import com.gedeshidai.shumadevelop.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 管理员接口
 *
 */
@RestController
@RequestMapping("/admin")
@Slf4j
public class AdminController {
    @Resource
    private UserService userService;


    /**
     * 审核通过
     */
    @PostMapping("/checkPass")
    @AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
    public BaseResponse<Boolean> checkPass(@RequestBody CheckRequest checkRequest){
        if(ObjectUtils.isEmpty(checkRequest)){
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        if(ObjectUtils.isEmpty(checkRequest.getId())){
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        return userService.checkPass(checkRequest);
    }

    /**
     * 审核驳回
     */
    @PostMapping("/reCheck")
    @AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
    public BaseResponse<Boolean> reCheck(@RequestBody CheckRequest checkRequest){
        if(ObjectUtils.isEmpty(checkRequest)){
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        if(ObjectUtils.isEmpty(checkRequest.getId())){
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        return userService.reCheck(checkRequest);
    }

    /**
     * 下线操作（单个/批量）
     * @param list
     * @return
     */
    @PostMapping("/setOffLine")
    @AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
    public BaseResponse<Boolean> setOffLine(@RequestBody List<Long> list){
        if(CollectionUtils.isEmpty(list)){
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        return userService.setOffLine(list);
    }

    /**
     * 上线操作（单个/批量）
     * @param list
     * @return
     */
    @PostMapping("/setOnLine")
    @AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
    public BaseResponse<Boolean> setOnLine(@RequestBody List<Long> list){
        if(CollectionUtils.isEmpty(list)){
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        return userService.setOnLine(list);
    }
}
